package com.qf.serevice.impl;

import com.qf.entity.Medicinei;
import com.qf.entity.Medicineii;

import com.qf.mapper.MedicineMapper;
import com.qf.pojo.BaseResult;
import com.qf.serevice.MedicineService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MedicineServiceImpl implements MedicineService {

    BaseResult baseResult = new BaseResult();
    @Resource
    MedicineMapper medicineMapper;

    @Override
    public BaseResult findByIdMedicine(Integer midi) {
        List<Medicinei> byIdMedicine = medicineMapper.findByIdMedicine(midi);
        if (byIdMedicine!=null){
            baseResult.setCode(1);
            baseResult.setData(byIdMedicine);
            return baseResult;
        }else {
            baseResult.setInfo("查找数据有误");
            return baseResult;
        }
    }

    @Override
    public BaseResult addMedicine(Medicineii medicineii) {
        Integer i = medicineMapper.addMedicine(medicineii);
        if(i>0){
            baseResult.setCode(1);
            baseResult.setInfo("添加成功！");
            return baseResult;
        }else {
            baseResult.setCode(0);
            baseResult.setInfo("添加失败！");

        }
        return baseResult;
    }

    @Override
    public BaseResult updateMedicine(Medicineii medicineii) {
        Integer integer = medicineMapper.updateMedicine(medicineii);
        if (integer>0){
            baseResult.setCode(1);
            baseResult.setInfo("修改成功！");
            return baseResult;
        }else {
            baseResult.setCode(0);
            baseResult.setInfo("修改失败！");
        }
        return baseResult;
    }

    @Override
    public BaseResult deleteMedicineById(Integer midii) {
        Integer integer = medicineMapper.deleteMedicineById(midii);
        if (integer>0){
            baseResult.setCode(1);
            baseResult.setInfo("删除成功！");
            return baseResult;
        }else {
            baseResult.setCode(0);
            baseResult.setInfo("删除失败！");
        }
        return baseResult;

    }
}
